$(function(){
    /*查询帖子列表*/
       ym.ajax({
        url: "/communication/quertCommunicationList",
        success: function (data) {
          var newData=JSON.parse(data);
           if (newData.obj) {
            console.log(typeof data)
                var dis = newData.obj;
                var length = dis.length;
                var topListHTML = "";
                var imgNavHTML="";
                var answerHTML="";
                var answerCount="";
                $('.am-header-title').html("<a href='#title-link' class='co-fff'>"+dis[0].exchange.userName+"的话题</a>");
                for (var i = 0; i < length; i++) {
                    if(dis[i].ymAttachments.length!==0){
                        for (var j = 0; j < dis[i].ymAttachments.length; j++) {
                            imgNavHTML+="<li><img src=http://cos-vc.cdaxkj.cn/"+dis[i].ymAttachments[j].attachmentUrl+"></li>"
                        }
                        
                    }else{
                       imgNavHTML="";
                    }
                    if(dis[i].ymAnswers.length!==0){
                        for (var k = 0; k < dis[i].ymAnswers.length; k++) {
                            answerHTML+="<li>"+
                                        "<div class='topic'>"+
                                        "<img src="+dis[i].ymAnswers[k].headimgurl+">"+
                                        "<div class='introduce'>"+
                                        "<h4>"+dis[i].ymAnswers[k].userName+"</h4>"+
                                        "<span class='times'>"+dis[i].ymAnswers[k].createTimeString+"</span>"+
                                        "</div>"+
                                        "</div>"+
                                        "<p class='current'>"+dis[i].ymAnswers[k].answerDes+"</p>"+
                                        // "<div class='commentsarea'>"+
                                        // "<ul class='am-padding-xs'>"+
                                        // "<li><span>毛毛<i style='color: #69e600;'>回复</i>我：</span>爽肤水对方的方式爽肤水对方的方式爽肤水对方的方式爽肤水对方的方式爽肤水对方的方式</li>"+
                                        // "</ul>"+
                                        // "</div>"+
                                        "</li>";
                        }
                    answerCount+="<span>查看<i class='prompt'>"+dis[i].ymAnswers.length+"</i>条回复</span><i >></i>";
                    }else{
                      answerHTML=""; 
                      answerCount="";
                    }
                    topListHTML+="<li curIndex='"+dis[i].exchange.exchangeId+"'>"+
                                "<div class='article-content'>"+
                                "<div class='topic'>"+
                                "<img src='"+dis[i].exchange.headimgurl+"'>"+
                                "<div class='introduce'>"+
                                "<h4>"+dis[i].exchange.userName+"</h4>"+
                                "<span>"+dis[i].exchange.createTimeString+"</span>"+
                                "</div>"+
                                "</div>"+
                                "<p>"+dis[i].exchange.ecchangeMessage+"</p>"+
                                "<ul class='am-avg-sm-3 am-text-center kcyy1 font1 am-margin-top-sm'>"+imgNavHTML+"</ul>"+
                                "<ul class='discusstopic answer-tab' style='margin-top: 1rem;'>"+answerHTML+"</ul>"+
                                "</div>"+
                                "<div class='am-block font14 w95 margintopxs article-foot'>"+
                                "<span onclick='window.location.href='detailedreply.html''>"+answerCount+"<i style='color:#fff'>></i></span>"+
                                "<span class='icon'>"+
                                "<img src='../img/pinglun.png'>"+
                                "<i>回复</i>"+
                                "</span>"+
                                "</div>"+
                                "</li>";
                }
                $('.content-tab').append(topListHTML);
            }
        }
    }); 
    window.setTimeout(function(){
        /*帖子详情*/
        $('.content-tab > li .article-content').click(function(){
            var curIndex=$(this).parent()[0].attributes['0'].nodeValue;
            ym.ajax({
            url: "/communication/quertCommunicationDetail",
            param:{
                exchangeId:curIndex,
                userId:'1'
            },
            success: function (data) {
               var newData=JSON.parse(data);
               if (newData.obj) {
                  var jsonData=newData.obj[0];
                  /*window.location.href='./../html/articleXq.html';
                  window.localStorage.setItem("articleXq",JSON.stringify(jsonData));*/
                }
            }
            });
        })
        /*回复评论*/
        $('.content-tab > li .article-foot').click(function(){
            var curIndex=$(this).parent()[0].attributes['0'].nodeValue;
            //$('.pinlun-input textarea').attr('placeholder','回复'+persoName+'：');
            $('.release button').click(function(){
                ym.ajax({
                    url: "/communication/insertConsult",
                    param:{
                        url:'/communication/quertCommunicationList',
                        answerDes:$('.release textarea').val(),
                        typeId:curIndex,
                        answerUserId:"1"
                    },
                    success: function (data) {
                       var newData=JSON.parse(data);
                       if (newData.obj) {
                          console.log(data)
                        }
                    }
                });
            })
        })
    },1500)
})